package cn.yiya.shiji.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cn.yiya.shiji.R;
import cn.yiya.shiji.entity.NotifyListItem;

/**
 * Created by chenjian on 2015/10/22.
 */
public class MessageCentListAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<NotifyListItem> mLists;
    private int nType;

    public MessageCentListAdapter(Context mContext, ArrayList<NotifyListItem> mLists, int nType) {
        this.mContext = mContext;
        this.mLists = mLists;
        this.nType = nType;
    }

    @Override
    public int getCount() {
        if (mLists == null)
            return 0;
        return mLists.size();
    }

    @Override
    public Object getItem(int position) {
        return mLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            if (nType == 1) {
                convertView = LayoutInflater.from(mContext).inflate(R.layout.msg_logistics_list_item, parent, false);
                holder = new ViewHolder();
                holder.tvOrderNo = (TextView) convertView.findViewById(R.id.msg_order_no);
                holder.tvTime = (TextView) convertView.findViewById(R.id.msg_logistics_date);
                holder.tvDesc = (TextView) convertView.findViewById(R.id.msg_logistics_des);
            } else {
                convertView = LayoutInflater.from(mContext).inflate(R.layout.message_center_expand_item_listview, parent, false);
                holder = new ViewHolder();
                holder.tvTime = (TextView) convertView.findViewById(R.id.tv_child_date);
                holder.tvDesc = (TextView) convertView.findViewById(R.id.tv_child_des);
            }
            convertView.setTag(holder);
        } else
            holder = (ViewHolder)convertView.getTag();

        NotifyListItem info = mLists.get(position);
        if (nType == 1) {
            holder.tvOrderNo.setText(info.getContent().getSub_order_num());
            holder.tvTime.setText(info.getTime().substring(0,10));
            holder.tvDesc.setText(info.getDes());
        } else {
            holder.tvTime.setText(info.getTime().substring(0,10));
            holder.tvDesc.setText(info.getDes());
        }

        return convertView;
    }

    public class ViewHolder{
        TextView tvDesc;
        TextView tvTime;
        TextView tvOrderNo;
    }
}
